<?php 
include_once('inc/init.php');
include_once('inc/functions.new-finger.php');
include_once('inc/functions.index.php');

// Define some variables.
$error_msg = "";
$for = "";
$why = "";
$email = "";
$name = "";
$newFingerId = 0;
$newFingerFor = '';

// Verify if the form was sent.
if (isset($_REQUEST['sent'])) {
  $for = stripslashes($_REQUEST['for']);
  $why = stripslashes($_REQUEST['why']);
  $_SESSION['new_finger_for'] = $for;
  $_SESSION['new_finger_why'] = $why;

  if (strlen($for)==0) {
    $error_msg .= "<p> '<strong>The finger for</strong>' field is empty. </p>";
  }
  if (strlen($why)==0) {
    $error_msg .= "<p> '<strong>Why finger it</strong>' field is empty. </p>";
  }

  if (strlen($error_msg)==0) {
    // Verify if logged
    if (isset($_SESSION['ses_email'])) {
      $email = $_SESSION['ses_email'];
    } else {
      header("Location: login.php?next=".urlencode(full_url()));
      exit();
    }
    // Add!
    $error_msg = Finger_create($for, $why);
    $newFingerFor = $for;
  }
} else {
  if (isset($_SESSION['new_finger_for']))
    $for = $_SESSION['new_finger_for'];
  if (isset($_SESSION['new_finger_why']))
    $why = $_SESSION['new_finger_why'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>New Finger</title>
    <?php include_once('template/head.php');?>
  </head>

  <body>
    <div id="wrap">
      <!-- header -->
      <?php include_once('template/header.php'); ?>
      <!-- body -->
      <div id="body">
        <h1>Add a new finger by filling the following form</h1>
        <div class="body">
          <?php if (strlen($error_msg)>0) { ?>
          <div class="error">
              <?php echo $error_msg; ?>
          </div>
            <?php } ?>

          <?php if (isset($_REQUEST['sent']) && strlen($error_msg)==0) { ?>
          <p class="form_item" style="height:66px;">
            <span class="label">You're done!</span>
            <span class="desc">Your finger has been added!</span>
            <span style="float:left">
              <input type="submit" class="orange_btn" value="Continue" id="submit_btn" onclick="javascript:window.location='<?php echo Finger_link($newFingerFor, $newFingerId); ?>'" />
            </span>
          </p>
            <?php } else { ?>
          <div style="width:550px; float: left;">
          <form name="newFinger" action="new-finger.php" method="post">
            <p class="form_item">
              <span class="label"> The finger for: </span>
              <span class="desc"> The finger for who? Or.. for what? </span>
              <input type="hidden" name="sent" value="yes" />
              <input value="<?php echo $for; ?>" type="text" id="for" name="for" class="inputwb wide5x" onchange="javascript:newFinger_updateSubmit();" />
            </p>
            <p class="form_item">
              <span class="label"> Why finger it: </span>
              <span class="desc"> Why do you finger it? Why does it bother you?
					Why don't you like it? What's wrong about it?						</span>
              <textarea name="why" class="inputwb wide5x" rows="5" cols="60" style="font-size:14px;"><?php echo $why; ?></textarea>
            </p>

            <p class="form_item" style="height:52px;">
              <span class="desc">Submit!</span>
              <span style="float:left">
                  <?php
                  if (strlen($for)>60) {
                    $for = substr($for,1,60)."..";
                  }
                  if (strlen($for)>0) {
                    $for = $for."!";
                  }
                  ?>
                <input type="submit" class="orange_btn" value="The Finger For <?php echo $for; ?>" id="submit_btn" />
              </span>
            </p>
          </form>
          </div>
          <div style="width:230px; float: right;">
            <img src="<?php echo BASE_URL; ?>img/banner1_228x171.gif" style="margin-bottom: 3px;" />
          <br />
          <strong>If you'd like to put this banner on your website use the following code:</strong>
          <input class="inputwb" onclick="javascript:this.select();" style="width: 220px;margin-top: 3px;" value='<a href="http://www.thefingerfor.com" target="_blank"><img alt="Banner TheFingerFor" src="http://www.thefingerfor.com/img/banner1_228x171.gif" border="0" /></a>' />
          </div>
          <div class="clearer"></div>
            <?php } ?>
        </div>
      </div>
      <!-- footer -->
      <?php include_once('template/footer.php'); ?>
    </div>
    <br /><br /> <!-- keep some space with the bottom -->
  </body>
</html>
<?php mysql_close($db); ?>